﻿using System.Windows;
using System.Windows.Data;

namespace theeg.DependencyAnalysis.CommonAddin.Behaviors
{
    public static class ViewSourceGroupBehavior
    {
        public static readonly DependencyProperty GroupNameProperty =
            DependencyProperty.RegisterAttached("GroupName", typeof(string), typeof(ViewSourceGroupBehavior), new PropertyMetadata(default(string), PropertyChangedCallback));

        private static void PropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
        {
            var viewSource = (CollectionViewSource)dependencyObject;
            ViewSourceGroup.AddToGroup(viewSource, (string)e.NewValue);
        }

        public static void SetGroupName(CollectionViewSource viewSource, string value)
        {
            viewSource.SetValue(GroupNameProperty, value);
        }

        public static string GetGroupName(CollectionViewSource viewSource)
        {
            return (string)viewSource.GetValue(GroupNameProperty);
        }
    }
}
